package com.example.novelweb.service.impl;


import com.example.novelweb.constant.UserConstant;
import com.example.novelweb.model.vo.UserVO;
import com.example.novelweb.service.NovelService;
import com.example.novelweb.service.PermissionService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class PermissionServiceImpl implements PermissionService {

  // @Lazy : novelService 嵌套使用 PermissionService
  @Lazy
  @Resource
  private NovelService novelService;


  @Override
  public Boolean checkNovelOwnerRight(Long userId, Long novelId) {
    Long count = novelService.query().eq("id",novelId).eq("userId",userId).count();
    return count>0;
  }

  @Override
  public Boolean checkAdminRight(UserVO userVO) {
    return Objects.equals(userVO.getRole(), UserConstant.ADMIN_ROLE);
  }


}
